package com.cc.flyingfish.controller;

import com.cc.flyingfish.annotation.IgnoreResponseAdvice;
import com.cc.flyingfish.util.FastDFSUtil;
import com.cc.flyingfish.vo.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author CHENCHEN
 * @title
 * @createTime 2023-03-11 14:26
 */
@RestController
public class FastDFSController {

    @Autowired
    private FastDFSUtil fastDFSUtil;

    @GetMapping("slices")
    public void slices(@RequestParam("file") MultipartFile file) throws Exception {
        fastDFSUtil.convertFileToSlices(file);
    }

    @GetMapping("video-slices")
    public CommonResponse<String> videoSlices(@RequestParam("file") MultipartFile file, String filePath, Integer sliceNo, Integer totalSliceNo) throws Exception {
        return CommonResponse.SUCCESS("",fastDFSUtil.uploadFileBySlices(file,filePath, sliceNo, totalSliceNo));
    }

    @IgnoreResponseAdvice
    @GetMapping("getVideo")
    public void videoSlices(HttpServletRequest request, HttpServletResponse response, String path){

        try {
            fastDFSUtil.viewVideoOnlineBySlices(request,response,path);
        } catch (Exception e) {

        }
    }


}
